import os
path = os.getcwd()+"\\サクラメントの十二宫 乱れる仔ひつじと手懐く狼\\"
dirs = os.listdir(path+"ExtractInnerQuota\\")
pernum = 179 #行数/字数比向上取整
count = 0
for dir in dirs:
    print(dir)
    f1 = open(path+"ExtractInnerQuota\\"+dir,"r",encoding='utf-8')
    text_lines = f1.readlines()
    num = len(text_lines)//pernum
    print(num)
    count = 0
    while count < num:
        #for text in text_lines[count*pernum:(count+1)*pernum-1]:
        n = count*pernum
        list = []
        while n < (count+1)*pernum:    
            if text_lines[n] == "\n":
                n += 1
            else:
                list.append(text_lines[n].strip("\n"))
                n += 1
        with open(path+"Slice\\"+dir.strip(".txt")+"0"+str(count)+".txt","w",encoding="utf-8") as f2:
            for ScriptText in list:
                f2.write(ScriptText+"\n")
            f2.close()
        with open(path+"Translated\\"+dir.strip(".txt")+"0"+str(count)+"(tled).txt","w",encoding="utf-8") as f3:
            f3.close()
        count += 1
    n = count*pernum
    list = []
    while n < len(text_lines):
        if text_lines[n] == "\n":
            print("空行")
            n += 1
        else:
            list.append(text_lines[n].strip("\n"))
            n += 1
    with open(path+"Slice\\"+dir.strip(".txt")+"0"+str(count)+".txt","w",encoding="utf-8") as f2:
            for ScriptText in list:
                f2.write(ScriptText+"\n")
            f2.close()
    with open(path+"Translated\\"+dir.strip(".txt")+"0"+str(count)+"(tled).txt","w",encoding="utf-8") as f3:
        f3.close()
    f1.close()